package org.example.controller;


import org.example.domain.User;
import org.example.response.ApiResponse;
import org.example.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
//@CrossOrigin(origins = "http://localhost:8081")
@RestController
@RequestMapping("/api")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/user/login")
    public ApiResponse<Map<String,Object>> login(@RequestBody User user){
        Map<String,Object> userInfo = loginService.Login(user);
        return ApiResponse.success(userInfo);
    }

    @GetMapping("/logout/{userId}")
    public ApiResponse<String> logout(@PathVariable Long userId){
        loginService.logout(userId);
        return ApiResponse.success("退出成功~");
    }
}
